let xlsx = require("node-xlsx");
let fs = require("fs");

let a = xlsx.parse("./导表/技能表.xlsx");
let table = a[0].data;

//fs.writeFileSync('./test.js', "pango11111");
//let text = fs.readFileSync('./test.js', 'utf-8');
let load = "module.exports = {";
for (let i = 1; i < table.length; i++) {
    let lst = table[i];
    let id = lst[0];
    let name = lst[1];
    let desc = lst[2];
    let program = lst[4] || "";
    let insert = "";

    try {
        //try catch 防止报错
        let s = fs.readFileSync(
            `../assets/script/skill/skill${id}.js`,
            "utf-8"
        );
        let lstCode = s.split("\n"); //对字符串按行分割，得到切割后的数字
        let flag = 0;
        for (let ss of lstCode) {
            if (ss.indexOf("===start===") != -1) {
                //indexOf(元素) 返回元素在字符串中的索引，找不到返回-1
                flag = 1;
            } else if (ss.indexOf("===end===") != -1) {
                break;
            } else if (flag) {
                insert += ss + "\n";
            }
        }
    } catch {}

    let code = `
let { CBaseSkill } = require("./baseSkill"); //导入，右边是对象，左边才能使用{右边对象的键名}这样定义

class CSkill${id} extends CBaseSkill {
    //子类构造要调用父类构造
    constructor() {
        super(); //当子类继承父类后，子类构造要调用父类构造
        this.id = ${id};
        this.name = "${name}";
        this.desc = "${desc}";
        this.program = [${program}];
    }

    //=========start=========
${insert}    //=========end===========
}

module.exports = CSkill${id}; //导出类
    `;
    fs.writeFileSync(`../assets/script/skill/skill${id}.js`, code);
    load += `
    ${id}:require("./skill${id}"),`;
}
load += "\n}";
fs.writeFileSync("../assets/script/skill/load.js", load);
